//
//  HOTMineListViewController.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-4.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTOrenoCateListViewController.h"
#import "HOTOrenoCateListCell.h"
#import "HOTAddMineViewController.h"
#import "HOTOrenoListViewController.h"
#import "NSString+extend.h"

@interface HOTOrenoCateListViewController ()

@property(nonatomic,strong)NSArray *dataList;

@end


@implementation HOTOrenoCateListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_oreno"]];
    [self setNaviTitle:@"俺のシリーズ"];
    
    _contentLab1.font = ZZZ_fontWithName(kHOT_FONT_ROUNDED_X, 12);
    _contentLab2.font = ZZZ_fontWithName(kHOT_FONT_ROUNDED_X, 12);
    _contentLab3.font = ZZZ_fontWithName(kHOT_FONT_ROUNDED_X, 12);
    _contentLab4.font = ZZZ_fontWithName(kHOT_FONT_ROUNDED_X, 12);
    
    _contentLab1.textColor = [UIColor whiteColor];
    _contentLab2.textColor = [UIColor whiteColor];
    _contentLab3.textColor = [UIColor whiteColor];
    _contentLab4.textColor = [UIColor whiteColor];
    
    [self requestDataList];
}

#pragma mark - UItableView DataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellId = @"cellID";
    HOTOrenoCateListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    
    if (cell == nil) {
        
        UINib *nib = [UINib nibWithNibName:XIB(@"HOTOrenoCateListCell") bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:cellId];
        
        cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    }
    
    NSDictionary *dic = [self.dataList objectAtIndex:indexPath.row];
    
    cell.contentLab.text = [[dic objectForKey:@"category_name"] toStr];
    
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataList.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 52;
}

#pragma mark - UITableView Delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dic = [self.dataList objectAtIndex:indexPath.row];
    NSString *cid = [dic objectForKey:@"category_id"];
    HOTOrenoListViewController *mdlvc = [[HOTOrenoListViewController alloc] initWithNibName:@"HOTOrenoListViewController" bundle:nil category_id:[HOTUtils getString:cid]];
    
    [self.navigationController pushViewController:mdlvc animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)requestBtnClicked:(id)sender {
    
    HOTAddMineViewController *amVC = [[HOTAddMineViewController alloc] initWithNibName:@"HOTAddMineViewController" bundle:nil];
    
    [self.navigationController pushViewController:amVC animated:YES];
}

#pragma mark - 私有方法

-(void)requestDataList {
    
    [self showLoading];
    
    NSDictionary *parameters = @{REQ_KEY_USER_TOKEN:self.userInfo.token,
                                 REQ_KEY_USER_ID:self.userInfo.userId};
    
    __unsafe_unretained HOTOrenoCateListViewController *tempObj = self;
    [self requestWithURL:HOT_URL_MY_SERIES_CATE_LIST Parameters:parameters success:^(NSInteger result, NSArray * data) {
        
        [tempObj loadingSuccess];
        
        tempObj.dataList = data;
        
        [_tableView reloadData];
        
    } failure:nil];
}
@end
